#include"comm.hpp"

int main()
{
    //获取key
    key_t k = get_key();
    printf("0x%x\n",k);

    //获取shmid---共享内存的id
    int shmid = creat_shmid(k);
    printf("shmid:%d\n",shmid);


    //获取mem_ad---共享内存的address
    char* mem_ad = (char*)attach_shm(shmid);
    printf("serever attach success...address is %p\n",mem_ad);

    int cnt = 10;
    while(cnt--)
    {
        printf("client say:%s\n",mem_ad);
        struct shmid_ds ds;
        shmctl(shmid,IPC_STAT,&ds);

        printf("获取属性:size:%d, pid:%d\n",ds.shm_segsz,ds.shm_cpid);
        sleep(1);
    }

    //去关联
    detach_shm(mem_ad);
    sleep(10);
    //销毁共享内存区域
    del_shm(shmid);
    return 0;
}